;; Plant P-system definitions with output membrane using Turtle language as defined in:
;; Prusinkiewicz, Przemyslaw; Lindenmayer, Aristid (1990). The Algorithmic Beauty of Plants. Springer-Verlag. 
;;
;; Copyright 2011:
;; James McDermott <jamesmichaelmcdermott@gmail.com>
;; Mark Wagy <mark.wagy@gmail.com>
;;
;; This file is part of p-gen, a p-systems and evolutionary system
;; written in Clojure.
;;
;; p-gen is licensed under GNU GPL v3.
;;
;; http://code.google.com/p/p-gen/

(use 'psystem.psys)
(load-file "map.clj")
(load-file "object-mappings.clj")
(load-file "turtle.clj")

(import myturtle.Turtle)

(def o+ (make-obj ['+]))
(def o- (make-obj ['-]))
(def oPUSH (make-obj ['push]))
(def oPOP (make-obj ['pop]))
(def oF (make-obj ['F]))
(def oX (make-obj ['X]))

(def r-abop-a (make-rule [oF] [oF oPUSH o+ oF oPOP oF oPUSH o- oF oPOP oF]))
(def r-abop-c (make-rule [oF] [oF oF o- oPUSH o- oF o+ oF o+ oF oPOP o+ oPUSH o+ oF o- oF o- oF oPOP]))
(def r-abop-f-1 (make-rule [oX] [oF o- oPUSH oPUSH oX oPOP o+ oX oPOP o+ oF oPUSH o+ oF oX oPOP o- oX]))
(def r-abop-f-2 (make-rule [oF] [oF oF]))


(def m-abop-a (make-membrane 1 [r-abop-a] [oF]))
(def m-abop-c (make-membrane 1 [r-abop-c] [oF]))
(def m-abop-f (make-membrane 1 [r-abop-f-1 r-abop-f-2] [oX]))

(def p-abop-a (make-psystem [m-abop-a] [1]))
(def p-abop-c (make-psystem [m-abop-c] [1]))
(def p-abop-f (make-psystem [m-abop-f] [1]))

(def cmdz-abop-a (value-mapper (get-output-vals p-abop-a) valmap-basic-turtle))
(def cmdz-abop-c (value-mapper (get-output-vals (psystem.psys/enumerate-psystem p-abop-c 4)) valmap-basic-turtle))
(def cmdz-abop-f (value-mapper (get-output-vals (psystem.psys/enumerate-psystem p-abop-f 4)) valmap-extended-turtle))

;; example session in the REPL:
;; 
;; (init-turtle)
;; (turtle-interpret cmdz-abop-f)
;; (draw-turtle 600)
